package com.ruoyi.mobile.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.mobile.domain.ShMarketEntity;
import com.ruoyi.system.api.resp.ShMarketResp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 商品分销信息Mapper接口
 */
@Mapper
@DS("master")
public interface IShMarketMapper extends BaseMapper<ShMarketEntity> {
    @Select("SELECT create_by as createBy,product_id as productId,"+
            "sum(amount) as amount,sum(market_amount) as marketAmount "+
            "FROM sh_market where create_by=#{createBy} and product_id in (SELECT id FROM sh_product WHERE product_type<=80 and app_id=#{appId}) "+
            "group by create_by,product_id order by create_time desc")
    public List<ShMarketResp> getMarketPayList1(@Param("createBy")Long createBy, @Param("appId")String appId);

    @Select("SELECT create_by as createBy,product_id as productId,"+
            "sum(amount) as amount,sum(market_amount) as marketAmount "+
            "FROM sh_market where create_by=#{createBy} and product_id in (SELECT id FROM sh_product WHERE product_type>90 and app_id=#{appId}) "+
            "group by create_by,product_id order by create_time desc")
    public List<ShMarketResp> getMarketPayList2(@Param("createBy")Long createBy, @Param("appId")String appId);

    @Select("SELECT create_by as createBy,product_id as productId,"+
            "sum(amount) as amount,sum(market_amount) as marketAmount "+
            "FROM sh_market where create_by=#{createBy} and product_id in (SELECT id FROM sh_product WHERE product_type>80 and product_type<=90 and app_id=#{appId}) "+
            "group by create_by,product_id order by create_time desc")
    public List<ShMarketResp> getMarketPayList3(@Param("createBy")Long createBy, @Param("appId")String appId);

    @Select("SELECT create_by as createBy,product_id as productId,"+
            "sum(amount) as amount,sum(market_amount) as marketAmount "+
            "FROM sh_market where create_by=#{createBy} and product_id in (SELECT id FROM sh_product WHERE product_type=#{productType} and app_id=#{appId}) "+
            "group by create_by,product_id order by create_time desc")
    public List<ShMarketResp> getMarketPayList(@Param("createBy")Long createBy, @Param("productType")Integer productType, @Param("appId")String appId);
}